package com.chenglu.android.restaurant.mvp.presenter;





import com.chenglu.android.bean.SmsCodeBean;
import com.chenglu.android.cart.bean.CartBean;
import com.chenglu.android.common.base.BasePresenter;
import com.chenglu.android.common.net.Constant;
import com.chenglu.android.common.net.RxScheduler;
import com.chenglu.android.common.net.exception.NetErrorException;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.common.utils.ToastUtils;
import com.chenglu.android.goodsinfo.bean.GoodsCommentBean;
import com.chenglu.android.goodsinfo.bean.GoodsInfoBean;
import com.chenglu.android.goodsinfo.bean.ShopsinfoBean;
import com.chenglu.android.index.bean.IndexRecomBean;
import com.chenglu.android.mine.bean.CommonDataBean;
import com.chenglu.android.restaurant.bean.CurrentShopsInfoBean;
import com.chenglu.android.restaurant.bean.GoodscategorylisBean;
import com.chenglu.android.restaurant.bean.ReviewTypeCountBean;
import com.chenglu.android.restaurant.bean.ShopReviewPageBean;
import com.chenglu.android.restaurant.mvp.contract.RestaurantShopContract;
import com.chenglu.android.restaurant.mvp.model.RestaurantShopoModel;

import java.util.Map;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import okhttp3.RequestBody;


/**
 * @author: lyj
 * @Created by Copyright 2023/7/27 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 *
 */
public class RestaurantShopPresenter extends BasePresenter<RestaurantShopContract.View> implements RestaurantShopContract.RestaurantShopPresenter {

     private  RestaurantShopContract.RestaurantShopoModel model;

    public RestaurantShopPresenter(){
        model = new RestaurantShopoModel();
    }



    @Override
    public void getCurrentShopsInfo(String tenantId) {
        if(!isViewAttached()){
            return;
        }
        model.getCurrentShopsInfo(tenantId)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<CurrentShopsInfoBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();

                    }

                    @Override
                    public void onNext(@NonNull CurrentShopsInfoBean bean) {

                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getCurrentShopsInfo(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }

    @Override
    public void getGoodscategoryList(String tenantId) {
        if(!isViewAttached()){
            return;
        }
        model.getGoodscategoryList(tenantId)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<GoodscategorylisBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();

                    }

                    @Override
                    public void onNext(@NonNull GoodscategorylisBean bean) {

                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getGoodscategoryList(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }

    @Override
    public void getReviewTypeCount(String tenantId) {
        if(!isViewAttached()){
            return;
        }
        model.getReviewTypeCount(tenantId)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<ReviewTypeCountBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();

                    }

                    @Override
                    public void onNext(@NonNull ReviewTypeCountBean bean) {

                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getReviewTypeCount(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }

    @Override
    public void getShopReviewPage(String tenantId, int current, int size, int isBad, int isPic) {
        if(!isViewAttached()){
            return;
        }
        model.getShopReviewPage(tenantId,current,size,isBad,isPic)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<ShopReviewPageBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();

                    }

                    @Override
                    public void onNext(@NonNull ShopReviewPageBean bean) {

                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getShopReviewPage(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }


    @Override
    public void getAddCartShop(String token, RequestBody requestBody) {
        if(!isViewAttached()){
            return;
        }
        model.getAddCartShop(token, requestBody)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<CommonDataBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();
//                        LogUtils.e("qqqqqqq:"+"onSubscribe");
                    }

                    @Override
                    public void onNext(@NonNull CommonDataBean bean) {
//                        LogUtils.e("qqqqqqq:"+"onNext");

//                        mView.getUserInfoSuccess(bean);
                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getAddCartShop(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
//                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }


    @Override
    public void getShopsCartList(String token, String shopsTypeId) {
        if(!isViewAttached()){
            return;
        }
        model.getShopsCartList(token, shopsTypeId)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<CartBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();
//                        LogUtils.e("qqqqqqq:"+"onSubscribe");
                    }

                    @Override
                    public void onNext(@NonNull CartBean bean) {
//                        LogUtils.e("qqqqqqq:"+"onNext");

//                        mView.getUserInfoSuccess(bean);
                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getShopsCartList(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
//                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }


    @Override
    public void getShopCouponreceive(String token, String id) {
        if(!isViewAttached()){
            return;
        }
        model.getShopCouponreceive(token, id)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new Observer<CommonDataBean>() {
                    //订阅
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        mView.showLoading();
//                        LogUtils.e("qqqqqqq:"+"onSubscribe");
                    }

                    @Override
                    public void onNext(@NonNull CommonDataBean bean) {
//                        LogUtils.e("qqqqqqq:"+"onNext");

//                        mView.getUserInfoSuccess(bean);
                        if(bean.getCode()==(Constant.HTTPCODE200)){
                            mView.getShopCouponreceive(bean);
                        }else {
                            ToastUtils.show(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        mView.dismissLoading();
                        NetErrorException.apiError(e,mView);
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
//                        LogUtils.e("qqqqqqq:"+"onComplete");

                    }
                });
    }

}
